package com.arlen.centre.controller.fegin;

import com.arlen.centre.mapper.WxUserMapper;
import com.arlen.centre.service.WxAccessToken;
import com.arlen.centre.service.WxUserService;
import com.arlen.common.dto.WxUserListDTO;
import com.arlen.common.feign.CenterClient;
import com.arlen.common.po.WxUserMesPO;
import com.arlen.common.result.Result;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("user")
public class FeignApi implements CenterClient {

    @Autowired
    WxAccessToken wxAccessToken;

    @Autowired
    WxUserService wxUserService;

    @Autowired
    WxUserMapper wxUserMapper;


    @Override
    public WxUserMesPO queryById(long id) {
        Result accessToken = null;
        try {
            accessToken = wxAccessToken.getAccessToken("wx4a506e6aef352faa", "1a4ff7439361546a99768d01a182351d");
        } catch (IOException e) {
            e.printStackTrace();
        }
        String token = accessToken.getData().toString();
        WxUserListDTO wxUserListDTO = wxUserService.listUser(token, null);
        List<String> openids = wxUserListDTO.getData().getOpenid();

        WxUserMesPO wxUserMesPO = wxUserService.getUserMes(token, openids.get(0), null);

        return wxUserMesPO;

    }
}
